package cn.usian.controller;

import cn.usian.blockhandler.GlobalBlockHandler;
import cn.usian.fallback.GlobalFallback;
import cn.usian.feign.ConsumerFeignClient;
import cn.usian.pojo.User;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class ConsumerController{
    @Autowired
    private ConsumerFeignClient consumerFeignClient;



    @GetMapping("getUserById/{id}")
    @SentinelResource(value = "getUserById",
                                blockHandlerClass = GlobalBlockHandler.class,
                                blockHandler = "blockHandlerMethod",
                                fallbackClass = GlobalFallback.class,
                                fallback = "fallbackMethod")
    public User getUserById(@PathVariable("id") Integer id) {
//        try {
//            Thread.sleep(3000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        return consumerFeignClient.getUserById(id);
    }
}
